//
// Created by Administrator on 2023/11/24.
//
#include "bits/stdc++.h"

using namespace std;

const int N=7;

bool st[N];
int path[N];
int n;

void dfs(int x){
    if(x==n){
        for (int i = 0; i < n; ++i)
            cout<<path[i];
        cout<<endl;
        return;
    }
    for (int i = 1; i <= n; ++i) {
        if(!st[i]){
            path[x]=i;
            st[i]= true;
            dfs(x+1);
            st[i]= false;
        }
    }

}

int main(){
    cin>>n;
    dfs(0);
}